module test_mesh_mod

use pFUnit

use test_base_mod

use mesh_mod

!> Overload the pFUnit assert for mesh objects
interface assertEqual
    !module procedure assertEqual_meshObj
end interface

contains

!> Run all of the tests for mesh_mod.
subroutine Run_Mesh_Tests()
    type(TestSuite_type)  :: suite
    type(TestResult_type) :: result

    ! Build suite from test procedures:
    suite = TestSuite( 'Test mesh_mod' )
    call add ( suite, TestCase1Step ( 'Test_Mesh_Create',   Test_Mesh_Create ) )
    call add ( suite, TestCase1Step ( 'Test_Axis_Build',    Test_Axis_Build  ) )
    result = newTestResult ( mode=MODE_USE_STDOUT )

    call Run('mesh_mod', suite, result)

    call clean( result )
    call clean( suite )
end subroutine Run_Mesh_Tests

!> Test the mesh creation routine.
subroutine Test_Mesh_Create()
    type(MeshObj) :: msh
    xLimits = [-5.0, 5.0]
    yLimits = [-5.0, 5.0]
    zLimits = [-5.0, 5.0]
    xCells  = 2
    yCells  = 2
    zCells  = 2
    msh = Mesh()
    call AssertEqual([-5.0,0.0,5.0], msh%axis_x, "x-axis")
    call AssertEqual([-5.0,0.0,5.0], msh%axis_y, "y-axis")
    call AssertEqual([-5.0,0.0,5.0], msh%axis_z, "z-axis")
end subroutine Test_Mesh_Create

!> Test the Axis_Build subroutine.
subroutine Test_Axis_Build()
    real :: xx(11), xrange(2)
    xrange = [-1.0, 9.0]
    call Axis_Build(xx, xrange)
    call assertEqual(44.0, sum(xx), "Axis vector")
end subroutine Test_Axis_Build

end module test_mesh_mod
